package com.tarena.lbs.basic.web.ex;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice("com.tarena.lbs.basic.web.controller")
@Slf4j
public class BasicGlobalExceptionHandler {
    @ExceptionHandler(Throwable.class)
    public Result handleThrowable(Throwable e) {

        log.error("系统异常", e);
        return Result.fail();
    }
    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException e) {
        log.error("业务异常", e);
        return Result.fail(e);
    }
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public Result handleArgumentException(MethodArgumentNotValidException e) {
        log.error("参数异常", e);
        BusinessException exception=new BusinessException("-3",e.getMessage());
        return Result.fail(exception);
    }


}
